package cn.groupmarket.types.design.framework.tree;

import lombok.Getter;
import lombok.Setter;

public abstract class AbstractStrategyRouter<T,D,R> implements StrategyMapper<T,D,R>,StrategyHandler<T,D,R>{

    @Getter
    @Setter
    protected StrategyHandler<T,D,R> defaultHandler = StrategyHandler.DEFAULT;

    public R router(T requestParameter,D dynamicContext) throws Exception{
        StrategyHandler<T,D,R> strategyHandler = get(requestParameter, dynamicContext);
        if (strategyHandler != null) {
            return strategyHandler.apply(requestParameter,dynamicContext);
        }else return defaultHandler.apply(requestParameter,dynamicContext);
    }
}
